package com.tencent.service.impl;

import com.tencent.mapper.RistMapper;
import com.tencent.service.RistService;
import com.tencent.utils.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import static com.tencent.utils.IdUtil.tl;

@Service
public class RistServiceImpl implements RistService {

    @Autowired(required = false)
    private RistMapper ristMapper;


    @Override
    public void rist1(String gender, Integer id) {
        Integer selectone = ristMapper.selectId(id);
        if (selectone!=null){
            ristMapper.update1(gender, id);
        }else {
            ristMapper.insert1(gender, id);
        }
    }

    @Override
    public void rist2(String gender, Integer id) {
        Integer selecttwo = ristMapper.selectId(id);
        if (selecttwo!=null){
            ristMapper.update2(gender, id);
        }else {
            ristMapper.insert2(gender, id);
        }
    }

        @Override
        public void rist3(String gender,Integer id){
            Integer integer1 = Integer.valueOf(gender);
            String selectone = ristMapper.selectone(id);
            String selecttwo = ristMapper.selecttwo(id);
            Integer s1 = Integer.valueOf(selectone);
            Integer s2 = Integer.valueOf(selecttwo);
            integer1 += s1 + s2;
            if (integer1 == 3 || integer1 == 4) {
                integer1 = 100;
                String s = Integer.toString(integer1);
                ristMapper.update(s, id);
            } else if (integer1 == 5 || integer1 == 6 || integer1 == 7) {
                integer1 = 200;
                String s = Integer.toString(integer1);
                ristMapper.update(s, id);
            } else if (integer1 == 8 || integer1 == 9 || integer1 == 10) {
                integer1 = 300;
                String s = Integer.toString(integer1);
                ristMapper.update(s, id);
            } else if (integer1 == 11 || integer1 == 12) {
                integer1 = 400;
                String s = Integer.toString(integer1);
                ristMapper.update(s, id);
            }
        }
    }
